<template>
	<view class="question">
		<!-- 主页背景图 -->
		<image src="./image/questionBgimg.png" class="bgimg"></image>
		<!-- 未支付时的按钮 -->
		<view class="buttonsBox" v-if="isPayment === '0'">
			<view class="btn" @click="voice">
				<image src="./image/btn1.png" mode="heightFix"></image>
			</view>
			<view class="btn" @click="voice">
				<image src="./image/btn2.png" mode="heightFix"></image>
			</view>
		</view>
		<!-- 支付成功后的按钮 -->
		<view class="buttonsBox threeBtns" v-else>
			<view class="btn" @click="router('/pages/questions/expertPage')">
				<image src="./image/btn1.png" mode="heightFix"></image>
			</view>
			<view class="btn">
				<image src="./image/btn3.png" mode="heightFix"></image>
			</view>
			<view class="btn" @click="router('/pages/questions/searchPage')">
				<image src="./image/btn2.png" mode="heightFix"></image>
			</view>
		</view>
		<!-- 消息 -->
		<question :speakData='itemData'></question>
		<!-- 跳转 支付 遮罩层 -->
		<el-dialog title="提示" :visible.sync="dialogVisible" :before-close="handleClose" :close-on-click-modal='false'>
			<text @click="payment">确认支付1.00元</text>
			<view class="bottom" @click="dialogVisible = false">取消</view>
		</el-dialog>
		<!-- 跳转 分享 遮罩层 -->
		<el-dialog title="提示" :visible.sync="dialogVisible2" :before-close="handleClose2" class='mackTiao'
			:close-on-click-modal='false'>
			<!-- :close-on-click-modal='false' 不允许点击空白处关闭遮罩层 -->
			<view class="con">
				<view @click="shareIcon">
					<image src="./image/朋友圈.png" mode="heightFix"></image>
				</view>
				<view @click="shareIcon">
					<image src="./image/微信好友.png" mode="heightFix"></image>
				</view>
				<view @click="shareIcon">
					<image src="./image/QQ好友.png" mode="heightFix"></image>
				</view>
				<view @click="shareIcon">
					<image src="./image/QQ空间.png" mode="heightFix"></image>
				</view>
				<view @click="shareIcon">
					<image src="./image/微博.png" mode="heightFix"></image>
				</view>
			</view>
		</el-dialog>
	</view>
</template>

<script>
	import time from  './js/time.js'
	import question from './noPages/question.vue'
	export default {
		data() {
			return {
				dialogVisible: false,
				dialogVisible2: false,
				isPayment: '0',
				data: {},
				itemData: []
			};
		},
		components: {
			question
		},
		methods: {
			// 遮罩层自带事件
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
					})
					.catch(_ => {});
			},
			handleClose2(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
					})
					.catch(_ => {});
			},
			router(path) {
				uni.navigateTo({
					url: path
				})
			},
			// 点击付款事件
			voice() {
				if (this.data.isPayment === '0') {
					this.dialogVisible = true
				} else {
					uni.showToast({
						title: '您已成为专家，无需再次支付',
						duration: 2000,
						icon: "none"
					});
				}
			},
			// 确认支付1元
			payment() {
				this.dialogVisible = false
				this.data.isPayment = '1'
				this.$api.putMjtQuestion(this.data).then(res => {
					// console.log(res)
					if (res.code == 200) {
						this.getMjtQuestionData()
					}
				})

			},
			// 分享的小图标
			shareIcon() {
				uni.showToast({
					title: '分享成功',
					duration: 2000,
					success: (res) => {
						// console.log(res)
						this.dialogVisible2 = false
					}
				})
			},
			// 获取是否成为专家
			getMjtQuestionData() {
				this.$api.getMjtQuestion().then(res => {
					// console.log(res)
					if (res.code == 200) {
						this.data = res.data[0]
					}
				})
			},
			// 获取公开的 提问数据
			getMjtSpeakIsOpenData() {
				this.$api.getMjtSpeakIsOpen(1).then(res => {
					// console.log(res)
					if(res.code == 200) {
						this.itemData = res.data
					}
				})
			},
			// 时间戳转时间
			sjc(sjc) {
				return time(Number(sjc))
			}
		},
		created() {
			this.getMjtQuestionData()
			this.getMjtSpeakIsOpenData()
		},
		watch: {
			data: {
				handler(newValue, oldValue) {
					this.isPayment = newValue.isPayment
				},
				deep: true,
				immediate: true
			}
		}
	}
</script>

<style lang="less" scoped>
	.question {
		width: 100vw;
		// height: calc(100vh - 100upx - 88upx);
		margin: 0 0 20upx;
		padding: 0;
		background-color: rgb(240, 240, 240);

		.bgimg {
			width: 100%;
			height: 30vh;
			// 以下三种解决图片基线问题
			vertical-align: top;
			// vertical-align: bottom;
			// display: block;
		}

		.buttonsBox {
			width: 100%;
			height: 12vh;
			display: flex;
			justify-content: space-between;

			.btn {
				width: 49%;
				height: 100%;
				background-color: white;
				box-sizing: border-box;
				padding: 3% 0;
				display: flex;
				justify-content: center;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.threeBtns {
			.btn {
				width: 32%;
			}
		}

		.item {
			width: 100%;
			height: 25vh;
			margin: 40upx 0;
			box-sizing: border-box;
			padding: 3%;
			background: white;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.itemTop {
				width: 100%;
				height: 25%;
				font-size: 26upx;
				display: flex;
				align-items: center;

				image {
					width: 20%;
					height: 100%;
				}
			}

			.itemBottom {
				width: 100%;
				height: 15%;
				font-size: 26upx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.conBox {
					width: 50%;
					height: 100%;
					font-size: 24upx;
					color: grey;
					display: flex;
					justify-content: space-around;

					view {
						display: flex;
						align-items: center;

						image {
							height: 70%;
						}

						text {
							margin-left: 10upx;
						}
					}

				}
			}

			.Content {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-evenly;

				text {
					display: block;
					font-size: 26upx;
					height: 40%;
					overflow: hidden; //超出的文本隐藏
					display: -webkit-box;
					-webkit-line-clamp: 2; // 超出多少行
					-webkit-box-orient: vertical;
				}

				view {
					height: 40%;
					display: flex;
					align-items: center;
					justify-content: flex-end;

					image {
						height: 100%;
					}

					image:first-child {
						height: 80%;
						margin-right: 10upx;
					}
				}
			}
		}

		::v-deep .el-dialog {
			width: 70%;
			height: 15vh;
			margin-top: 35vh !important;
			border-radius: 24upx;
			overflow: hidden;
		}

		::v-deep .el-dialog__header,
		.el-dialog__footer {
			display: none;
		}

		::v-deep .el-dialog__body {
			height: 100%;
			padding: 0;
			display: flex;
			flex-direction: column;

			text {
				display: block;
				height: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 40upx;
				text-align: center;
				border-bottom: 2upx solid rgba(203, 203, 203, 0.5);
			}

			.bottom {
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 36upx;
			}
		}

		.mackTiao ::v-deep .el-dialog {
			width: 80%;
			height: 25vh;
			border-radius: 16upx;
		}

		.mackTiao ::v-deep .el-dialog__body {
			width: 100%;
			height: 100%;

			.con {
				height: 100%;
				display: flex;
				flex-wrap: wrap;
				align-items: center;

				view {
					width: 33%;
					height: 40%;
					text-align: center;

					image {
						height: 100%;
					}
				}

			}
		}
	}
</style>
